package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.payconfig.EntityRechargeRule;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.XfRechargeRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/11/10
 **/
@Slf4j
@RestController
public class RechargeRuleController {

	@Autowired
	private  XfRechargeRuleService xfRechargeRuleService;

	@PostMapping(PayConfigUrl.Url_getRechargeRule)
	public Result getRechargeRule(Long companyId,  @RequestParam(value = "subAccount",required = false,defaultValue = "0") Integer subAccount){
//		List<EntityRechargeRule> list =  xfRechargeRuleService.getRechargeRule(companyId);
		List<EntityRechargeRule> list =  xfRechargeRuleService.getRechargeRule(companyId,subAccount);
		return ResultUtil.success(list);
	}

	@PostMapping(PayConfigUrl.Url_setRechargeRule)
	public Result setRechargeRule(@RequestBody EntityRechargeRule entityRechargeRule){
		Boolean boo = xfRechargeRuleService.setRechargeRule(entityRechargeRule.getComId(),entityRechargeRule);
		if(boo){
			return ResultUtil.success();
		}
		return ResultUtil.error(ResultEnum.Err_3014);
	}

	@PostMapping(PayConfigUrl.Url_deleteRechargeRule)
	public Result deleteRechargeRule(@RequestBody EntityRechargeRule entityRechargeRule){
		Boolean boo = xfRechargeRuleService.deleteRechargeRule(entityRechargeRule.getComId(),entityRechargeRule);
		if(boo){
			return ResultUtil.success();
		}
		return ResultUtil.error(ResultEnum.Err_3016);
	}




}
